from etgui import *
from PageLayout import *
from FontBox import *

def MakePageAppearance(model):
	path="GUI.Appearance.WindowFont"+'.'
	if IsWindows():
		return MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeBorderedSectionLayout("Fonts for Titles, Menu Names, and Entries",
				FontBox(model,path+"System")
			),
			MakeBorderedSectionLayout("Fonts for Lists of Symbols",
				FontBox(model,path+"Fixed")
			)
		)
	else:   # Unix
		#look=PotGuiOneOf("WindowSystem.Look",eVObjHExpand,gPoint64,Point(0,1))   # for test
		look=PotGuiOneOf("WindowSystem.Look")
		#look.AddItem("ET",0)   # will not be supported :-(
		look.AddItem("Motif",1)
		look.AddItem("Windows",2)
		return MakePageLayout(eVObjHExpand|eVObjVCenter,
			MakeBorderedSectionLayout("Look",
				look
			),
			MakeBorderedSectionLayout("Fonts for Titles, Menu Names, and Entries",
				FontBox(model,path+"System")
			),
			MakeBorderedSectionLayout("Fonts for Lists of Symbols",
				FontBox(model,path+"Fixed")
			)
		)

class LookColorSwitcher:
	def __init__(self,model,slot,box,items):
		model.AddModelObserver(self,slot)
		self.slot=slot
		self.box=box
		self.items=items
	def __call__(self,model,slot):
		v=Cast(model).GetValue(self.slot)
		if v==1:	# Motif
			self.box.SetAt(0,self.items[0])
		elif v==2:	# Windows
			self.box.SetAt(0,self.items[1])
		else:		# Unknown -> use Motif
			self.box.SetAt(0,self.items[0])	    

def MakePageWindowColors(model):
	path="GUI.Appearance.WindowColor"+'.'
	motif_colors=Form(
		items=[
			"View Background Color",PotGuiColorSelector(path+"ViewBackground",Point(128,16)),
			"Window Background Color",PotGuiColorSelector(path+"WindowBackground",Point(128,16)),
			"Highlight Color",PotGuiColorSelector(path+"Highlight",Point(128,16)),
			"Disable Color",PotGuiColorSelector(path+"Disable",Point(128,16)),
			"Caret Color",PotGuiColorSelector(path+"Caret",Point(128,16)),
		]
	)
# XXX colors for windows look under unix...
#    windows_colors=Form(
#	items=[
#	    "View Background Color",PotGuiColorSelector(path+"ViewBackground",Point(128,16)),
#	    "Highlight Color",PotGuiColorSelector(path+"Highlight",Point(128,16)),
#	    "Caret Color",PotGuiColorSelector(path+"Caret",Point(128,16)),
#	]
#    )
	windows_colors=MultilineTextItem("Colors cannot be customized for the @BWindows Look@B")
 
	color_items=[]
	color_items.append(motif_colors)
	color_items.append(windows_colors)
	color_box=AlignBox(
		align=eVObjHFixed,
		flags=eVObjVFixed,
		inner=motif_colors
	)
	LookColorSwitcher(model,"WindowSystem.Look",color_box,color_items)
	return MakePageLayout(eVObjHCenter|eVObjVCenter,
		MakeSectionLayout(color_box)
	)
